package com.cmaq.activities;

import com.cmaq.database.SQLController;
import com.example.soapcliente.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;


public class ModifyToolActivity  extends Activity implements OnClickListener {

    EditText et, etCode, enabled;
    Button delete_bt;
    String estado;
    long member_id;

    SQLController dbcon;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        
        super.onCreate(savedInstanceState);
        setContentView(R.layout.modify_tool);

        dbcon = new SQLController(this);
        dbcon.open();

        et = (EditText) findViewById(R.id.name_id);
        etCode = (EditText) findViewById(R.id.code_id);
        delete_bt = (Button) findViewById(R.id.delete_bt_id);
        enabled = (EditText) findViewById(R.id.enabled_id);
        Intent i = getIntent();
        String memberID = i.getStringExtra("memberID");
        String memberName = i.getStringExtra("memberName");
        String memberCode = i.getStringExtra("memberCode");
        String memberEnabled = i.getStringExtra("memberEnable");
        
        member_id = Long.parseLong(memberID);
        if(this.getIntent().getExtras() != null){
    		estado = (String)this.getIntent().getExtras().get("estado");
        }
        et.setText(memberName);
        et.setEnabled(false);
        etCode.setText(memberCode);
        etCode.setEnabled(false);
        delete_bt.setOnClickListener(this);
        enabled.setText(memberEnabled);
        
    }

    @Override
    public void onClick(View v) {
     
        switch (v.getId()) {
          case R.id.delete_bt_id:
            dbcon.deleteData(member_id);
            this.returnHome();
            break;
          case R.id.cancelar_bt_id:
        	  Intent main = new Intent(ModifyToolActivity.this, MainActivity.class)
	          .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	    	  startActivity(main);   
        	break;
        }
    }

    public void returnHome() {

        Intent home_intent = new Intent(getApplicationContext(),
                ToolsListActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        home_intent.putExtra("estado", estado);

        startActivity(home_intent);
    }

}
